package com.wzapp.sitposture.config;

import com.querydsl.jpa.impl.JPAQueryFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

import javax.annotation.PostConstruct;
import javax.persistence.EntityManager;
import javax.persistence.PersistenceContext;

/**
 * Created by qianglong on 2018/4/9.
 */
@Configuration
public class QueryFactory {

    @Autowired
    @PersistenceContext
    private EntityManager entityManager;

    //实例化控制器完成后执行该方法实例化JPAQueryFactory
    @PostConstruct
    @Bean
    public JPAQueryFactory initFactory()
    {
        System.out.println("开始实例化JPAQueryFactory");
        return new JPAQueryFactory(entityManager);
    }
}
